#!/usr/bin/env bash
# -*- coding: utf-8 -*-

# if ! command -v nvim && (! vim --version | grep '+python3' 1>/dev/null); then
#     echo 'vim should be installed with python3'
#     exit 1
# fi
# if ! command -v clang-format; then
#     if command -v yum; then
#         sudo yum install -y clang
#     elif command -v apt; then
#         sudo apt install -y clang-format
#     elif command -v brew; then
#         brew install clang-format
#     else
#         echo "please install clang-format"
#     fi
# fi


current=$(pwd)

rm -rf ~/.vimrc ~/.vim ~/.config/nvim
mkdir -p ~/.config
ln -s ~/.config/nvim ~/.vim
git clone --recursive https://gitee.com/zkdfbb/vim.git .config/nvim
cd ~/.config/nvim

mkdir -p ~/.local
test -e ~/.zshrc && echo "export PATH=~/.local/bin:\$PATH" >> ~/.zshrc
test -e ~/.bashrc && echo "export PATH=~/.local/bin:\$PATH" >> ~/.bashrc
test -e ~/.zshrc && echo "alias vim=nvim" >> ~/.zshrc
test -e ~/.bashrc && echo "alias vim=nvim" >> ~/.bashrc

if ! command -v node; then
    wget https://install-node.vercel.app/lts -O node.sh
    PREFIX=~/.local BASE_URL=https://mirrors.tuna.tsinghua.edu.cn/nodejs-release bash node.sh -f
    rm node.sh -f
fi

if ! command -v nvim; then
    tar xf nvim-linux64.tar.gz
    rsync -avP nvim-linux64/ ~/.local/
    rm -rf nvim-linux64
fi

tar xf plugged.tar.gz
cd $current

# echo | vim +PlugInstall +qall
# CocInstall coc-lists coc-highlight coc-pairs coc-css coc-html coc-go coc-json coc-markdownlint coc-highlight
